package com.jay.test.designModel.action.observer.javaSelf;

import java.util.Observable;
import java.util.Observer;

/**
 * Created by caoyuan7 on 2018/11/1.
 */
public class Watcher implements Observer {

    public Watcher(Observable o){
        o.addObserver(this);
    }

    @Override
    public void update(Observable o, Object arg) {

        System.out.println("状态发生改变：" + ((Watched) o).getData());
    }
    public static void main(String[] args) {

        //创建被观察者对象
        Watched watched = new Watched();
        //创建观察者对象，并将被观察者对象登记
        Observer watcher = new Watcher(watched);
        //给被观察者状态赋值
        watched.setData("start");
        watched.setData("start");
        watched.setData("run");
        watched.setData("stop");

    }

}
